package com.jsyh.maidu.adapter.home;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jsyh.maidu.R;
import com.jsyh.maidu.config.ConfigValue;
import com.jsyh.maidu.model.BestNewHot;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by ZHY_9 on 2017/7/11.
 */

public class CollectGridAdapter extends BaseAdapter {

    private Context context;
    private List<BestNewHot> datas;

    public CollectGridAdapter(Context context, List<BestNewHot> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder = null;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.collect_hot_grid, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.bindData(datas.get(position));

        return view;
    }

    class ViewHolder{
        private ImageView iv_goodsIcon;
        private TextView tv_goodsInfo, tv_nowPrice, tv_beforePrice;

        public ViewHolder(View view) {
            iv_goodsIcon = (ImageView) view.findViewById(R.id.iv_goodsIcon);
//            iv_cartIcon = (ImageView) view.findViewById(R.id.iv_cartIcon);
            tv_goodsInfo = (TextView) view.findViewById(R.id.tv_goodsInfo);
            tv_nowPrice = (TextView) view.findViewById(R.id.tv_nowPrice);
            tv_beforePrice = (TextView) view.findViewById(R.id.tv_beforePrice);
        }

        public void bindData(BestNewHot bestNewHot) {
            Picasso.with(context).load(ConfigValue.IMG_IP + bestNewHot.getGoods_img()).into(iv_goodsIcon);

            tv_goodsInfo.setText(bestNewHot.getGoods_name());
            tv_nowPrice.setText(bestNewHot.getShop_price());
            tv_beforePrice.setText(bestNewHot.getMarket_price());
            tv_beforePrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        }

    }
}
